﻿<UserControl x:Class="VNet.VisiSuite.Controls.ProductionControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vuc="clr-namespace:VNet.VisiSuite.Controls"
             xmlns:converter="clr-namespace:VNet.VisiSuite.Common.Converters;assembly=VNet.VisiSuite.Common"
             mc:Ignorable="d" 
             Loaded="onLoaded"
             x:Name="ProductionControlObject"
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converter:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        <converter:InvertBooleanVisibilityConverter x:Key="InvertBooleanVisibilityConverter" />
        <converter:IntObjectStringConverter x:Key="IntObjectStringConverter"/>
        <converter:ColorStringToColorConverter x:Key="ColorStringToColorConverter"/>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <DockPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  LastChildFill="True" >

            <Grid  Margin="16, 8, 0, 0" HorizontalAlignment="Left">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Label Grid.Row="0" Grid.Column="1" Style="{StaticResource CenterLabelStyle}">SKU</Label>
                <Label Grid.Row="0" Grid.Column="2" Style="{StaticResource CenterLabelStyle}">Job #</Label>
                <Label Grid.Row="0" Grid.Column="3" Style="{StaticResource CenterLabelStyle}">Pass</Label>
                <Label Grid.Row="0" Grid.Column="4" Style="{StaticResource CenterLabelStyle}">Quantity</Label>
                <Label Grid.Row="0" Grid.Column="5" Style="{StaticResource CenterLabelStyle}">Remaining</Label>

                <Label Grid.Row="1" Grid.Column="0" Style="{StaticResource RightLabelStyle}">Current:</Label>
                <TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource CurrentValueStyle}" Text="{Binding CurrentSku, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="1" Grid.Column="2" Style="{StaticResource CurrentValueStyle}" Width="100" Text="{Binding CurrentWorkOrder, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="1" Grid.Column="3" Style="{StaticResource CurrentValueStyle}" Width="50" Text="{Binding CurrentPass, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="1" Grid.Column="4" Style="{StaticResource CurrentValueStyle}" Width="75" HorizontalContentAlignment="Right" Text="{Binding CurrentQuantity, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="1" Grid.Column="5" Style="{StaticResource CurrentValueStyle}" Width="75" HorizontalContentAlignment="Right" Text="{Binding CurrentRemaining, Mode=OneWay}"></TextBox>

                <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource RightLabelStyle}">Next:</Label>
                <TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource NextValueStyle}" Text="{Binding NextSku, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="2" Grid.Column="2" Style="{StaticResource NextValueStyle}" Width="100" Text="{Binding NextWorkOrder, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="2" Grid.Column="3" Style="{StaticResource NextValueStyle}" Width="50" Text="{Binding NextPass, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="2" Grid.Column="4" Style="{StaticResource NextValueStyle}" Width="75" HorizontalContentAlignment="Right" Text="{Binding NextQuantity, Mode=OneWay}"></TextBox>
                <TextBox Grid.Row="2" Grid.Column="5" Style="{StaticResource NextValueStyle}" Width="75" HorizontalContentAlignment="Right" Text="{Binding NextRemaining, Mode=OneWay}"></TextBox>
            </Grid>

            <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{Binding DowntimeBackground}" Margin="10,12,0,4"  MouseLeftButtonDown="downtimeClick"  TouchUp="downtimeTouch" Visibility="{Binding DowntimeVisibility}" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Name="_col1" Width="{Binding DowntimeColumn1}" />
                        <ColumnDefinition x:Name="_col2" Width="{Binding DowntimeColumn2}" />
                        <ColumnDefinition x:Name="_col3" Width="{Binding DowntimeColumn3}" />
                    </Grid.ColumnDefinitions>
                    
                    <vuc:CircularProgessChart Grid.Column="0" x:Name="_pie" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisibleChanged="_pie_OnIsVisibleChanged" Visibility="{Binding CircularVisibility}" Width="80"/>
                    <vuc:CountDownTimer Grid.Column="0" x:Name="_countDownTimer" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding CountDownTimerVisibility}" TimeSpan="{Binding CountDownTime}" IsVisibleChanged="_countDownTimer_OnIsVisibleChanged" 
                                         Width="160"/>

                    <TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{Binding DowntimeForeground}" FontSize="16pt" TextAlignment="Center" Text="{Binding DowntimeDescription}" >
                    </TextBlock>
                    <TextBlock Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="{Binding DowntimeForeground}" FontSize="12pt" TextAlignment="Right" Text="Press to Change Status" Margin="0,0,10,6"
                               Visibility="{Binding PressToChangeVisibility}">
                    </TextBlock>
                </Grid>
            </Border>

        </DockPanel>

        <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom" IsHitTestVisible="False" Focusable="False" Margin="8,0,0,-12">
            <Label Style="{StaticResource AxisLabelStyle}"></Label>
            <Label Style="{StaticResource CenterLabelStyle}" Width="50" Margin="4,0,4,0" VerticalAlignment="Bottom">Target</Label>
            <Label Style="{StaticResource CenterLabelStyle}" Width="50" Margin="4,0,4,0" VerticalAlignment="Bottom">Good</Label>
            <Label Style="{StaticResource CenterLabelStyle}" Width="50" Margin="4,0,4,0" VerticalAlignment="Bottom">Defect</Label>
        </StackPanel>

        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" IsHitTestVisible="False" Focusable="False" Margin="0,0,0,-12">
            <Label Style="{StaticResource RightLabelStyle}">Target Cycle Time:</Label>
            <TextBox Style="{StaticResource CurrentValueStyle}" Width="50" Text="{Binding TargetCycleTime, Mode=OneWay}"></TextBox>
            <Label Style="{StaticResource RightLabelStyle}" Margin="8, 0, 0, 4">Average Cycle Time:</Label>
            <TextBox Style="{StaticResource CurrentValueStyle}" Width="50" Text="{Binding AverageCycleTime, Mode=OneWay}"></TextBox>
            <Label Style="{StaticResource RightLabelStyle}" Margin="8, 0, 0, 4">Target Load/Unload Time:</Label>
            <TextBox Style="{StaticResource CurrentValueStyle}" Width="50" Text="{Binding TargetLoadUnloadTime, Mode=OneWay}"></TextBox>
            <Label Style="{StaticResource RightLabelStyle}" Margin="8, 0, 0, 4">Average Load/Unload Time:</Label>
            <TextBox Style="{StaticResource CurrentValueStyle}" Width="50" Text="{Binding AverageLoadUnloadTime, Mode=OneWay}"></TextBox>
        </StackPanel>

        <Grid Grid.Row="2" Grid.Column="0" Margin="8,8,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="57" />
            </Grid.RowDefinitions>
            
            <ItemsControl Grid.Row="0" ItemsSource="{Binding Path= AxisDetails}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="1" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="2,2,2,2" Orientation="Horizontal" VerticalAlignment="Center" IsHitTestVisible="True" Focusable="True" MinHeight="1">
                        <Viewbox Style="{StaticResource SmallRectangleViewBoxDefaultStyle}" StretchDirection="DownOnly">
                            <Label Style="{StaticResource AxisLabelDefaultStyle}" Content="{Binding Path = Label, Mode=OneWay}" ></Label>
                        </Viewbox>
                        <Border Style="{StaticResource SmallRectangleStyle}">
                            <Viewbox HorizontalAlignment="Right" StretchDirection="DownOnly">
                                <Label Style="{StaticResource AxisLabelDefaultStyle}" Content="{Binding Path=Target, Mode=OneWay, Converter= {StaticResource IntObjectStringConverter}}" />
                            </Viewbox>
                        </Border>
                        <Border Style="{StaticResource SmallRectangleStyle}">
                            <Viewbox HorizontalAlignment="Right" StretchDirection="DownOnly">
                                <Label Style="{StaticResource AxisLabelDefaultStyle}" Content="{Binding Path=Good, Mode=OneWay, Converter= {StaticResource IntObjectStringConverter}}" Foreground="{Binding Path=Color, Mode=OneWay, Converter={StaticResource ColorStringToColorConverter}}" />
                            </Viewbox>
                        </Border>
                        <Button Style="{StaticResource SmallButtonRectangleStyle}" Command = "{Binding RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}, Path=DataContext.DefectClickCommand}" 
                                            CommandParameter="{Binding Path=Index}">
                            <Viewbox HorizontalAlignment="Right" StretchDirection="DownOnly" >
                                <Label Style="{StaticResource AxisLabelDefaultStyle}" Content="{Binding Path=Defect,  Mode=OneWay, Converter= {StaticResource IntObjectStringConverter}}" />
                            </Viewbox>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

            <Label Grid.Row="1" Style="{StaticResource CenterLabelStyle}" FontSize="14pt" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding Operator, Mode=OneWay}"></Label>

        </Grid>
        
        <vuc:ProductionMeterGraphControl Margin="4,12,4,12" Grid.Row="2" Grid.Column="1"
                                           StartTime="{Binding GraphStartTime}"
                                           EndTime="{Binding GraphEndTime}"
                                           Interval="{Binding GraphInterval}" Legend="{Binding GraphLegend}"
                                           DataPoints="{Binding GraphDataPoints}"
                                           RedrawError="{Binding RedrawError, Mode=OneWayToSource}"
                                           FontFamily="Segoe UI Semilight" FontSize="10pt" Foreground="#FF3F3F3F" />
    </Grid>
</UserControl>
